home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / PROPSHET.PAK / DISPATCH.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  168 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   dispatch.c
  9. //
  10. //  PURPOSE:  Implement the generic message and command dispatchers.
  11. //    
  12. //
  13. //  FUNCTIONS:
  14. //    DispMessage - Call the function associated with a message.
  15. //    DispCommand - Call the function associated with a command.
  16. //    DispDefault - Call the appropriate default window procedure.
  17. //
  18. //  COMMENTS:
  19. //
  20.  
  21. #include <windows.h>            // required for all Windows applications
  22. #include <windowsx.h>
  23. #include "globals.h"            // prototypes specific to this application
  24.  
  25. LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
  26.  
  27. //
  28. //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
  29. //
  30. //  PURPOSE: Call the function associated with a message.
  31. //
  32. //  PARAMETERS:
  33. //    lpmsdi - Structure containing the message dispatch information.
  34. //    hwnd - The window handle
  35. //    uMessage - The message number
  36. //    wparam - Message specific data
  37. //    lparam - Message specific data
  38. //
  39. //  RETURN VALUE:
  40. //    The value returned by the message function that was called.
  41. //
  42. //  COMMENTS:
  43. //    Runs the table of messages stored in lpmsdi->rgmsd searching
  44. //    for a message number that matches uMessage.  If a match is found,
  45. //    call the associated function.  Otherwise, call DispDefault to
  46. //    call the default function, if any, associated with the message
  47. //    structure.  In either case, return the value recieved from the
  48. //    message or default function.
  49. //
  50.  
  51. LRESULT DispMessage(LPMSDI lpmsdi, 
  52.                     HWND   hwnd, 
  53.                     UINT   uMessage, 
  54.                     WPARAM wparam, 
  55.                     LPARAM lparam)
  56. {
  57.      int  imsd;
  58.  
  59.     MSD *rgmsd = lpmsdi->rgmsd;
  60.     int  cmsd  = lpmsdi->cmsd;
  61.  
  62.     for (imsd = 0; imsd < cmsd; imsd++)
  63.     {
  64.         if (rgmsd[imsd].uMessage == uMessage)
  65.             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
  66.     }
  67.  
  68.     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
  69. }
  70.  
  71. //
  72. //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
  73. //
  74. //  PURPOSE: Call the function associated with a command.
  75. //
  76. //  PARAMETERS:
  77. //    lpcmdi - Structure containing the command dispatch information.
  78. //    hwnd - The window handle
  79. //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
  80. //      control, or accelerator.
  81. //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
  82. //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
  83. //
  84. //  RETURN VALUE:
  85. //    The value returned by the command function that was called.
  86. //
  87. //  COMMENTS:
  88. //    Runs the table of commands stored in lpcmdi->rgcmd searching
  89. //    for a command number that matches wCommand.  If a match is found,
  90. //    call the associated function.  Otherwise, call DispDefault to
  91. //    call the default function, if any, associated with the command
  92. //    structure.  In either case, return the value recieved from the
  93. //    command or default function.
  94. //
  95.  
  96.  
  97. LRESULT DispCommand(LPCMDI lpcmdi, 
  98.                     HWND   hwnd, 
  99.                     WPARAM wparam, 
  100.                     LPARAM lparam)
  101. {
  102.      WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
  103.      int     icmd;
  104.  
  105.     CMD    *rgcmd = lpcmdi->rgcmd;
  106.     int     ccmd  = lpcmdi->ccmd;
  107.  
  108.     // Message packing of wparam and lparam have changed for Win32,
  109.     // so use the GET_WM_COMMAND macro to unpack the commnad
  110.  
  111.     for (icmd = 0; icmd < ccmd; icmd++)
  112.     {
  113.         if (rgcmd[icmd].wCommand == wCommand)
  114.         {
  115.             return rgcmd[icmd].pfncmd(hwnd,
  116.                                       wCommand,
  117.                                       GET_WM_COMMAND_CMD(wparam, lparam),
  118.                                       GET_WM_COMMAND_HWND(wparam, lparam));
  119.         }
  120.     }
  121.  
  122.     return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
  123. }
  124.  
  125.  
  126. //
  127. //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
  128. //
  129. //  PURPOSE: Call the appropriate default window procedure.
  130. //
  131. //  PARAMETERS:
  132. //    edwp - Enumerate specifying the appropriate default winow procedure.
  133. //    hwnd - The window handle
  134. //    uMessage - The message number
  135. //    wparam - Message specific data
  136. //    lparam - Message specific data
  137. //
  138. //  RETURN VALUE:
  139. //    If there is a default proc, return the value returned by the
  140. //    default proc.  Otherwise, return 0.
  141. //
  142. //  COMMENTS:
  143. //    Calls the default procedure associated with edwp using the specified
  144. //    parameters.
  145. //
  146.  
  147. LRESULT DispDefault(EDWP   edwp, 
  148.                     HWND   hwnd, 
  149.                     UINT   uMessage, 
  150.                     WPARAM wparam, 
  151.                     LPARAM lparam)
  152. {
  153.     switch (edwp)
  154.     {
  155.         case edwpNone:
  156.             return 0;
  157.         case edwpWindow:
  158.             return DefWindowProc(hwnd, uMessage, wparam, lparam);
  159.         case edwpDialog:
  160.             return DefDlgProc(hwnd, uMessage, wparam, lparam);
  161.         case edwpMDIFrame:
  162.             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
  163.         case edwpMDIChild:
  164.             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
  165.     }
  166.     return 0;
  167. }
  168.